home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / comm / tm420_1.zip / TOOLBOX.EXE / TOOLBOX3.SCR < prev   
Text File  |  1995-06-14  |  12KB  |  405 lines

  1. ;
  2. ; TOOLBOX3.SCR (c) Copyright 1990-1992 by White River Software.
  3. ; All right reserved.
  4. ;
  5. ; Date written: 10 May 1990
  6. ; Revision:      1 Jan 1992
  7. ;
  8. ;
  9. ; This toolbox defines several procedures to access the phone
  10. ; directory and two procedures to calcuate the difference between
  11. ; two date/time strings.
  12. ;
  13. ; To use this toolbox, you should add the line
  14. ;    #include "toolbox3.scr"
  15. ; at the beginning of your script file.  This will increase the file
  16. ; size of the compiled script file .TMS by about 6K.  To minimum the
  17. ; overhead, you should cut and paste the procedures that you used into
  18. ; your script file.  For example, the <DiffTime> and <DiffDate>
  19. ; procedures may be excluded.
  20. ;
  21. ; The <PhoneDirectory> variable tells the Phone's procedures which
  22. ; phone directory is to be access.  Default is the TM.FON.
  23. ;
  24. ; Summary:
  25. ;
  26. ;   PhoneSize size
  27. ;   ; return the number of entries in the phone directory
  28. ;
  29. ;   PhoneFind name,number,startPoint
  30. ;   ; find an entry by <name> and return the entry number in <number>
  31. ;   ; starting from <startPoint>
  32. ;
  33. ;   PhoneRead number,name,password,linkscript,logfile,phone,total,last
  34. ;   ; read the <number>-th entry of <PhoneDirectory>
  35. ;   ; <total> is an integer variable
  36. ;
  37. ;   PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  38. ;   ; write the <number>-th entry of <PhoneDirectory>
  39. ;   ; <total> is an integer
  40. ;
  41. ;   ConvertDate format1,date1,format1,date2
  42. ;   ; convert the date string <date1> of format <format1> to
  43. ;   ; <date2> of <format2>
  44. ;
  45. ;   DiffDate date1,date2,days
  46. ;   ; <days> = <date2> - <date1>
  47. ;
  48. ;   DiffTime time1,time2,seconds
  49. ;   ; <seconds> = <time2> - <time1>
  50. ;
  51.  
  52. string PhoneDirectory
  53.  
  54. PhoneDirectory = "TM.FON"     ; phone directory to be accessed by
  55.                               ; the following procedures
  56.  
  57.  
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59. ;
  60. ; PhoneSize size
  61. ; function: calcuate the number of entires in the phone directory
  62. ;           <PhoneDirectory>
  63. ;
  64. Procedure PhoneSize integer size
  65. filesize PhoneDirectory,size
  66. size = size / 131             ; each entry is 131 bytes
  67. EndProc
  68.  
  69.  
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ;
  72. ; PhoneFind name,number,startPoint
  73. ; function: find an entry by <name> and return the entry number in <number>
  74. ;           starting from <startPoint>
  75. ; remark:   <number> is set to 0 if <name> is not found
  76. ;           <success> is FALSE if the phone directory cannot be open
  77. ;           To find from the beginning of the phone directory, use
  78. ;               PhoneFind name,number,1
  79. ;           To continue the search, use
  80. ;               PhoneFind name,number,number+1
  81. ; caution:  this function will close the formly opened file since the
  82. ;           OPEN command is used.  You should close the file before
  83. ;           issuing this command and reopen the file after this command
  84. ;
  85. Procedure PhoneFind string name,integer number,startPoint
  86. string entry
  87. integer pos,size
  88. PhoneSize size
  89. if startPoint>size            ; no more entries
  90.    number = 0                 ; report as not found
  91.    return
  92. endif
  93. number = startPoint-1
  94. if number<0
  95.    number = 0
  96. endif
  97. pos = 0
  98. open PhoneDirectory
  99. if success
  100.    seek number*131
  101.    While success and pos=0 and number<size
  102.       number = number+1
  103.       read entry                 ; read a phone entry
  104.       if success
  105.          strpos entry,name,pos   ; search for <name>
  106.          if pos>30
  107.             pos = 0              ; not in name field
  108.          endif
  109.       endif
  110.    EndWhile
  111.    close
  112. endif
  113. if pos=0
  114.    number = 0                 ; set <number> to 0 if not found
  115. endif
  116. EndProc
  117.  
  118.  
  119. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  120. ;
  121. ; PhoneRead number,name,password,linkscript,logfile,phone,total,last
  122. ; function: read the <number>-th entry of <PhoneDirectory>
  123. ; remark:   <success> is FALSE if the phone directory cannot be open
  124. ;           tailing spaces in each field are discarded
  125. ;           <total> is an integer variable, the others are string
  126. ;           variables
  127. ; caution:  this function will close the formly opened file since the
  128. ;           OPEN command is used.  You should close the file before
  129. ;           issuing this command and reopen the file after this command
  130. ;
  131. Procedure PhoneRead integer number,string name,password,linkscript,logfile,phone,integer total,string last
  132. string entry,totalstr
  133. integer size
  134.  
  135.    Procedure GetField string field,integer FieldLength,FieldOffset
  136.    integer len,orglen
  137.    string ch
  138.    substr entry,FieldOffset+1,FieldLength,field ; get the field
  139.    len = FieldLength
  140.    orglen = FieldLength       ; delete tailing space
  141.    ch = " "
  142.    While len>0 and ch=" "
  143.       substr field,len,1,ch
  144.       if ch=" "
  145.          len = len-1
  146.       endif
  147.    EndWhile
  148.    if orglen>len
  149.       strdel field,len+1,orglen-len
  150.    endif
  151.    EndProc
  152.  
  153. PhoneSize size
  154. open PhoneDirectory
  155. if success
  156.    if number<1
  157.       seek 0
  158.    elseif number>size
  159.       seek (size-1)*131
  160.    else
  161.       seek (number-1)*131     ; each entry is 131 bytes
  162.    endif
  163.    read entry
  164.    GetField name,30,0
  165.    GetField password,15,30
  166.    GetField linkscript,8,46
  167.    GetField logfile,8,55
  168.    GetField phone,20,64
  169.    GetField totalstr,5,96
  170.    atoi  totalstr,total
  171.    GetField last,8,103
  172.    close
  173. endif
  174. EndProc
  175.  
  176.  
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. ;
  179. ; PhoneWrite number,name,linkscript,logfile,password,phone,total,last
  180. ; function: write the <number>-th entry of <PhoneDirectory>
  181. ; remark:   <success> is FALSE if the phone directory cannot be open
  182. ;           <total> is an integer, the others are strings
  183. ;           To change only a field of the entry, you should use the
  184. ;           PhoneRead procedure to read the other fields of the entry,
  185. ;           otherwise, the other fields will be erased.
  186. ; caution:  this function will close the formly opened file since the
  187. ;           OPEN command is used.  You should close the file before
  188. ;           issuing this command and reopen the file after this command
  189. ;
  190. Procedure PhoneWrite integer number,string name,password,linkscript,logfile,phone,integer total,string last
  191. string totalstr
  192. integer EntryPos,size
  193.  
  194.    Procedure WriteField string field,integer FieldLength,FieldOffset,LeftJustify
  195.    integer len
  196.    string space
  197.    seek EntryPos+FieldOffset
  198.    length field,len
  199.    if len>FieldLength
  200.       strdel field,len+1,FieldLength-len
  201.    endif
  202.    if not LeftJustify and len<FieldLength
  203.       strset space," ",1,FieldLength-len
  204.       write space,
  205.    endif
  206.    write field,
  207.    if LeftJustfiy and len<FieldLength
  208.       strset space," ",1,FieldLength-len
  209.       write space,
  210.    endif
  211.    EndProc
  212.  
  213. PhoneSize size
  214. if number<1
  215.    EntryPos = 0
  216. elseif number>size
  217.    EntryPos = (size-1)*131
  218. else
  219.    EntryPos = (number-1)*131
  220. endif
  221. open PhoneDirectory
  222. if success
  223.    WriteField name,30,0,1
  224.    WriteField password,15,30,1
  225.    WriteField linkscript,8,46,1
  226.    WriteField logfile,8,55,1
  227.    WriteField phone,20,64,1
  228.    itoa  total,totalstr
  229.    WriteField totalstr,5,96,0
  230.    WriteField last,8,103,1
  231. endif
  232. close
  233. EndProc
  234.  
  235.  
  236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  237. ;
  238. ; ConvertDate format1,date1,format2,date2
  239. ; function: convert the date string <date1> of format <format1> to
  240. ;           <date2> of <format2>
  241. ;
  242. Procedure ConvertDate integer format1,string date1,integer format2,string date2
  243. string mm,dd,yy,separator,ch
  244. integer len
  245. length date1,len
  246. date2 = date1
  247. if format1<>format2 and len=8 and format1<=8 and format2<=8
  248.   switch format2        
  249.     case 0,1,2: separator = "-"         ; determine which separator
  250.     case 3,4,5: separator = "/"
  251.     case 6,7,8: separator = "."
  252.   endswitch
  253.   switch format1                        ; extract mm,dd,yy from date1
  254.     case 0,3,6: substr date1,1,2,mm
  255.                 substr date1,4,2,dd
  256.                 substr date1,7,2,yy
  257.     case 1,4,7: substr date1,1,2,dd
  258.                 substr date1,4,2,mm
  259.                 substr date1,7,2,yy
  260.     case 2,5,8: substr date1,1,2,yy
  261.                 substr date1,4,2,mm
  262.                 substr date1,7,2,dd
  263.   endswitch
  264.   substr mm,1,1,ch                      ; set " 1" to "01", etc
  265.   if ch=" "
  266.      strset mm,"0",1,1
  267.   endif
  268.   substr dd,1,1,ch
  269.   if ch=" "
  270.      strset dd,"0",1,1
  271.   endif
  272.   substr yy,1,1,ch
  273.   if ch=" "
  274.      strset yy,"0",1,1
  275.   endif
  276.   switch format2                        ; form the date string
  277.     case 0,3,6: date2 = mm
  278.                 concat date2,separator
  279.                 concat date2,dd
  280.                 concat date2,separator
  281.                 concat date2,yy
  282.     case 1,4,7: date2 = dd
  283.                 concat date2,separator
  284.                 concat date2,mm
  285.                 concat date2,separator
  286.                 concat date2,yy
  287.     case 2,5,8: date2 = yy
  288.                 concat date2,separator
  289.                 concat date2,mm
  290.                 concat date2,separator
  291.                 concat date2,dd
  292.   endswitch
  293.   substr date2,1,1,ch                   ; set "01-01-01" to " 1-01-01"
  294.   if ch="0"
  295.     strset date2," ",1,1
  296.   endif
  297. endif
  298. EndProc
  299.  
  300.  
  301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  302. ;
  303. ; DiffDate date1,date2,days
  304. ; function: calcuate the number of days between <date1> and <date2>
  305. ;           as if <days>=<date2>-<date1>
  306. ; remark:   <date1> and <date2> in MM-DD-YY format
  307. ;           if <date2> is less then <date1>, it is assumed that <date2>
  308. ;           pass a century
  309. ;           <days> is always a non-negative integer
  310. ;
  311. Procedure DiffDate string date1,date2,integer days
  312. integer z1, z2
  313.  
  314.    ; calcuate the elapsed days from 1st Jan 1800
  315.    Procedure CalcDays string dateStr,integer days
  316.    string yy,mm,dd
  317.    integer y,m,d
  318.    substr dateStr,7,2,yy      ; <dateStr> in MM-DD-YY format
  319.    substr dateStr,1,2,mm
  320.    substr dateStr,4,2,dd
  321.    atoi yy,y
  322.    atoi mm,m
  323.    atoi dd,d
  324.    days = (y+100)*365 + (y+99)/4
  325.    if m>1                     ; January
  326.       days = days + 31
  327.    endif                      ; Febrary
  328.    if m>2
  329.       if y = y/4*4
  330.          days = days + 29
  331.       else
  332.          days = days + 28
  333.       endif
  334.    endif
  335.    if m>3                     ; March
  336.       days = days + 31
  337.    endif
  338.    if m>4                     ; April
  339.       days = days + 30
  340.    endif
  341.    if m>5                     ; May
  342.       days = days + 31
  343.    endif
  344.    if m>6                     ; June
  345.       days = days + 30
  346.    endif
  347.    if m>7                     ; July
  348.       days = days + 31
  349.    endif
  350.    if m>8                     ; August
  351.       days = days + 31
  352.    endif
  353.    if m>9                     ; September
  354.       days = days + 30
  355.    endif
  356.    if m>10                    ; October
  357.       days = days + 31
  358.    endif
  359.    if m>11                    ; November
  360.       days = days + 30
  361.    endif
  362.    days = days + d
  363.    EndProc
  364.  
  365. CalcDays date1,z1             ; calculate elapsed days from 1st Jan 1800
  366. CalcDays date2,z2
  367. days = z2 - z1
  368. if days<0
  369.    days = days + 36500 + 25   ; pass a century
  370. endif
  371. EndProc
  372.  
  373.  
  374. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  375. ;
  376. ; DiffTime time1,time2,seconds
  377. ; function: calcuate the number of seconds between <time1> and <time2>
  378. ;           as if <seconds>=<time2>-<time1>
  379. ; remark:   <time1> and <time2> in HH:MM:SS format
  380. ;           if <time2> is less then <time1>, it is assumed that <time2>
  381. ;           pass mid-night
  382. ;           <seconds> is always a non-negative integer
  383. ;
  384. Procedure DiffTime string time1,time2,integer seconds
  385. integer h1,m1,s1,h2,m2,s2     ; <time1> and <time2> in "HH:MM:SS" format
  386. string hh,mm,ss
  387. substr time1,1,2,hh           ; get hour part
  388. substr time1,4,2,mm           ; get minuate part
  389. substr time1,7,2,ss           ; get second part
  390. atoi hh,h1                    ; convert to integer
  391. atoi mm,m1
  392. atoi ss,s1
  393. substr time2,1,2,hh           ; get hour,minuate and second from <time2>
  394. substr time2,4,2,mm
  395. substr time2,7,2,ss
  396. atoi hh,h2
  397. atoi mm,m2
  398. atoi ss,s2
  399. if h2<h1                      ; <time2> pass mid-night
  400.    h2 = h2 + 24
  401. endif
  402. seconds = (h2-h1)*3600 + (m2-m1)*60 + (s2-s1)
  403. EndProc
  404.  
  405.